package JavaEE_notes.common_API;

import com.wl.week_01.Student;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

/**
 * @description Arrays API, 对数组进行一系列操作
 * @author TaiZai
 * @data 2024/9/20 16:55
 */
public class api_Arrays {
    public static void main(String[] args) {
        Integer[] arr = {1, 2, 3, 4, 5};
        // 降序排序
        Arrays.sort(arr, Collections.reverseOrder());
        System.out.println(Arrays.toString(arr));

        // 操作类数组
        Student[] students = new Student[5];
        students[0] = new Student("Tom", 18, 1.75);
        students[1] = new Student("Jerry", 20, 1.85);
        students[2] = new Student("Lily", 19, 1.68);
        students[3] = new Student("Lucy", 17, 1.72);
        students[4] = new Student("Mike", 19, 1.80);

        // 按年龄升序
        Arrays.sort(students, Comparator.comparingInt(Student::getAge));
        // 按年龄降序
        Arrays.sort(students, Comparator.comparingInt(Student::getAge).reversed());

        // 按身高升序
        Arrays.sort(students, Comparator.comparingDouble(Student::getHeight));
        // 按身高降序
        Arrays.sort(students, Comparator.comparingDouble(Student::getHeight).reversed());
    }
}
